/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-05-20     甘泽       the first version
 */
#ifndef APPLICATIONS_BMP280_SENSOR_BMP280_H_
#define APPLICATIONS_BMP280_SENSOR_BMP280_H_

#include <rtthread_nano_device.h>
#include <stm32f4xx_hal.h>

// 测压范围（单位百帕）与温度范围（°C）
#define SENSOR_PRES_RANGE_MAX 110000
#define SENSOR_PRES_RANGE_MIN 30000
#define SENSOR_TEMP_RANGE_MAX 85
#define SENSOR_TEMP_RANGE_MIN -40

#define BMP280_CMD_SET_ODR 1      /* 设置ODR */
#define BMP280_CMD_SET_PWR_MODE 2 /* 设置供电模式 */

#define BMP280_USING_SPI

#define BMP280_SPI SPI1

#define BMP280_SPI_SCK_GPIO GPIOA
#define BMP280_SPI_SCK_PIN GPIO_PIN_5
#define BMP280_SPI_SCK_AF GPIO_AF5_SPI1

#define BMP280_SPI_MOSI_GPIO GPIOA
#define BMP280_SPI_MOSI_PIN GPIO_PIN_7
#define BMP280_SPI_MOSI_AF GPIO_AF5_SPI1

#define BMP280_SPI_MISO_GPIO GPIOA
#define BMP280_SPI_MISO_PIN GPIO_PIN_6
#define BMP280_SPI_MISO_AF GPIO_AF5_SPI1

#define BMP280_SPI_CS_GPIO GPIOC
#define BMP280_SPI_CS_PIN GPIO_PIN_4

#define BMP280_SPI_SCK_GPIO_RCC_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define BMP280_SPI_MISO_GPIO_RCC_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define BMP280_SPI_MOSI_GPIO_RCC_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define BMP280_SPI_CS_GPIO_RCC_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()

#define BMP280_SPI_RCC_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE()

#ifdef BMP280_USING_I2C

#define BMP280_I2C I2C1
#define BMP280_I2C_SCL_GPIO GPIOA
#define BMP280_I2C_SCL_PIN GPIO_PIN_0
#define BMP280_I2C_SCL_AF GPIO_AF4_I2C1

#define BMP280_I2C_SDA_GPIO GPIOA
#define BMP280_I2C_SDA_PIN GPIO_PIN_0
#define BMP280_I2C_SDA_AF GPIO_AF4_I2C1

#define BMP280_I2C_SCL_GPIO_RCC_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define BMP280_I2C_SDA_GPIO_RCC_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()

#define BMP280_I2C_RCC_ENABLE() __HAL_RCC_I2C1_CLK_ENABLE()

#define BMP280_I2C_ADDR BMP280_I2C_ADDR_PRIM

#endif

/// @brief 注册并启动bmp280
/// @param
/// @return
int start_bmp280(void);
#endif /* APPLICATIONS_BMP280_SENSOR_BMP280_H_ */
